package com.aaa.moneymanage.utils;

import com.aaa.entity.User;
import com.aaa.moneymanage.feign.UserFeign;
import com.aaa.utils.JWTUtils;
import com.aaa.utils.WebUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author ：XiaoxXuan
 * @date ：Created in 2023/4/4 10:52
 * @description：
 * @modified By：
 */
@Component
public class GetString {

    @Resource
    private UserFeign userFeign;

    public String getUsername(){
        //直接在token获取手机号
        HttpServletRequest request = WebUtil.getRequest();
        String token = request.getHeader("token");
        Map<String, Object> tokenInfo = JWTUtils.getInfo(token);
        String phone = tokenInfo.get("username").toString();

        User user = userFeign.getByUsername(phone);
        String userName = user.getUserName();

        return userName;
    }

}